SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Ruby

Ruby static code analysis

Unique rules to find Bugs, Security Hotspots, and Code Smells in your RUBY code

  • All rules 75
  • Bug17
  • Security Hotspot2
  • Code Smell56
 
Tags
    Impact
      Clean code attribute
        1. Modules should use "extend self" instead of "module_function"

           Code Smell
        2. Array and hash literals should be used instead of constructors when no parameters are needed

           Code Smell
        3. Logical operators "and" and "or" should be replaced with "&&" and "||"

           Code Smell
        4. Private methods should be declared at the end of Ruby classes

           Code Smell
        5. Predicate methods should not use redundant "is_" prefix

           Code Smell
        6. Controllers should inherit from appropriate base classes

           Code Smell
        7. Rails model callback methods should be private

           Code Smell
        8. Rails collections should use "ids" instead of "pluck(:id)" for primary keys

           Code Smell
        9. Rails queries should use "find_by" instead of "where.take" for single record retrieval

           Code Smell
        10. Safe navigation operator should be preferred over ActiveSupport's "try!"

           Code Smell
        11. HTTP status codes should use symbols instead of numeric values

           Code Smell
        12. Use "require_relative" instead of "require" for loading local files

           Code Smell
        13. "unless" statements should be used appropriately to avoid confusing logic

           Code Smell
        14. Asset compilation should be disabled in production environments

           Code Smell
        15. Enumerable methods should be used instead of "each" with "break" or "return"

           Code Smell
        16. Global variables should not be used in Rails applications

           Code Smell
        17. Direct "Thread.current" usage should be avoided in favor of safer alternatives

           Code Smell
        18. Bare rescue clauses should specify exception types

           Code Smell
        19. Require statements should be placed at the top of files

           Code Smell
        20. Exception classes should be used instead of raising generic strings

           Code Smell
        21. Use "Dir.chdir" instead of system calls for directory changes

           Code Smell
        22. Constants in modules should use explicit class scoping when they may be overridden by including classes

           Code Smell
        23. Explicit RuntimeErrors should be omitted in raise statements

           Code Smell
        24. Multi-line comments should not be empty

           Code Smell
        25. Methods should not have identical implementations

           Code Smell
        26. Cognitive Complexity of functions should not be too high

           Code Smell
        27. Ruby parser failure

           Code Smell
        28. Boolean checks should not be inverted

           Code Smell
        29. Two branches in a conditional structure should not have exactly the same implementation

           Code Smell
        30. "case" statements should not be nested

           Code Smell
        31. Unused local variables should be removed

           Code Smell
        32. "case" statements should not have too many "when" clauses

           Code Smell
        33. Track lack of copyright and license headers

           Code Smell
        34. Functions should not have too many lines of code

           Code Smell
        35. Control flow statements "if", "for", "while", "until", "case" and "begin...rescue" should not be nested too deeply

           Code Smell
        36. Octal values should not be used

           Code Smell
        37. "case" statements should have "else" clauses

           Code Smell
        38. "if ... else if" constructs should end with "else" clauses

           Code Smell
        39. Statements should be on separate lines

           Code Smell
        40. String literals should not be duplicated

           Code Smell
        41. Methods should not be empty

           Code Smell
        42. Unused function parameters should be removed

           Code Smell
        43. Function and block parameter names should comply with a naming convention

           Code Smell
        44. "case when" clauses should not have too many lines of code

           Code Smell
        45. Track uses of "TODO" tags

           Code Smell
        46. Track uses of "FIXME" tags

           Code Smell
        47. Redundant pairs of parentheses should be removed

           Code Smell
        48. Nested blocks of code should not be left empty

           Code Smell
        49. Functions should not have too many parameters

           Code Smell
        50. Expressions should not be too complex

           Code Smell
        51. Mergeable "if" statements should be combined

           Code Smell
        52. Tabulation characters should not be used

           Code Smell
        53. Files should not have too many lines of code

           Code Smell
        54. Lines should not be too long

           Code Smell
        55. Class names should comply with a naming convention

           Code Smell
        56. Method names should comply with a naming convention

           Code Smell

        Global variables should not be used in Rails applications

        adaptability - modular
        reliability
        maintainability
        Code Smell
        • rails
        • coupling
        • testing

        This rule raises an issue when global variables (prefixed with $) are used in Rails applications.

        Why is this an issue?

        How can I fix it?

        More Info

        Global variables create tight coupling between different parts of your Rails application, making your code harder to maintain and test.

        When you use global variables, you create hidden dependencies that are not obvious from looking at a class or method signature. This makes it difficult to understand what data a piece of code depends on, and it becomes nearly impossible to test components in isolation.

        Global variables also introduce the risk of unexpected side effects. Since they can be modified from anywhere in your application, tracking down bugs becomes much more challenging. In a multi-threaded environment like Rails, global variables can also lead to race conditions.

        Rails provides better alternatives for sharing data across your application. These alternatives are more explicit, easier to test, and follow Rails conventions.

        What is the potential impact?

        Using global variables can lead to:

        • Code that is difficult to test and debug
        • Tight coupling between unrelated parts of your application
        • Unexpected side effects and hard-to-track bugs
        • Race conditions in multi-threaded environments
        • Violation of Rails conventions and best practices
          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use